<HTML>
<HEAD>
<TITLE>
Installing the fonts in Netscape Navigator
</TITLE>
</HEAD>
<BODY>
<H2>
Installing the fonts in Netscape Navigator
</H2>

<tt>
by Sergey Babkin 
&lt;babkin@bellatlantic.net&gt;, &lt;sab123@hotmail.com&gt;
</tt>
<p>

This is a collection of supplements to Netscape 4.x on
Unix. Probably they will also work with Netscape 3.x,
possilby with minor modifications.
<p>

<h4><tt>
&nbsp;&nbsp;Makefile<br>
&nbsp;&nbsp;nsfix.c<br>
&nbsp;&nbsp;psfonts.cf
</tt></h4>
<p>

This is a program that allows to substitute the font metrics
of any PostScript font in Netscape. 
<p>

When Netscape prints the files to PostScript format it uses a 
built-in table of character widths. It prints all the fixed-width 
characters in the typeface "Courier" and all the variable-width 
characters in the typeface "Times". And if the PostScript printer
has these fonts by Adobe then everything goes fine because
the tables inside Netscape are generated from the Adobe fonts.
But if the fonts are different (say, those supplied with Ghostscripts
or the fonts with non-latin characters) then the result is quite
ugly. This program allows to replace the width tables inside
the Netscape executable with the tables for any given font.
The only problem is that Netscape can hold only one set of tables
at once. So if you want to print with different fonts (say,
for different languages or encodings) you will have to make
multiple copies of the executable, tune each of them for its
font and then run them separately.
<p>

I tried to make the program as machine-independent as possible.
But because it patches the binary files it still has the dependencies
on hardware. The default version as supplied was designed for
Intel x86 machines but it should work OK on any machine
with 32-bit CPU and 4Kbyte (or less) page size. If it can't
find the tables matching the font names on some other architecture
the first thing to try would be reduce the `<tt>PAGEBITS</tt>' definition
in the source code. On the machines with non-page-aligned structure
of executables it won't work at all. I don't know whether would
it work on the 64-bit machines. This may depend on whether the
Netscape executable was compiled in 32-bit or 64-bit mode. For
the 64-bit executables it may be neccessary to change the definition
of the type `<tt>tptr</tt>' to an 8-byte integer type (probably `<tt>long</tt>'
or `<tt>long long</tt>'). Also must be re-compiled for patching of the 
Netscape binary for each particular machine architecture because
it assumes the byte order of the current machine.
<p>

It might be possible to create a program that would patch
a running Netscape binary on the fly, that would allow
changing the printing fonts as neccessary when Netscape is
running. But this would be even more platform-dependent,
so I don't feel any enthusiasm about doing that.
<p>

I have tested the program on the Intel machines, Netscape
4.08 and 4.7, OS FreeBSD (both a.out and ELF formats of the
Netscape binary) and UnixWare.
<p>

After all these scary issues are resolved the compiling
is easy: just run `<tt>make</tt>'.
<p>

To command to patch the Netscape is:
<p>
<tt>
&nbsp;&nbsp;./nsfix <i>&lt;netscape-binary&gt; &lt;config-file&gt;</i>
</tt>
<p>

Please make a copy of the original Netscape binary before
patching in case anything goes wrong. Patch the copy, test
that it works OK and only then install it. The configuration
file describes the fonts that are to be used. An example
is provided in the file psfonts.cf.
<p>

Each line in the configuration file consists of 4
columns:
<p>

<tt><i>
&lt;PS_font_name&gt; &lt;font_base_file&gt; &lt;suffix_afm&gt; &lt;suffix_font&gt;
</i></tt>
<p>

For example, the following line from my configuration file:
<p>

<tt>
Courier /usr/lib/X11/fonts/ttf/cokoi8n.koi8-r .afm .pfa
</tt>
<p>

says that the font `Courier' will be replaced with the
font taken from the file `<tt>/usr/lib/X11/fonts/ttf/cokoi8n.koi8-r.pfa</tt>'
and the metrics for that font will be taken from the file
`<tt>/usr/lib/X11/fonts/ttf/cokoi8n.koi8-r.afm</tt>' .
<p>

One more caveat: the new font must have a proper encoding
table. Some fonts contain characters for multiple encodings
hoping that the program wil re-encode them as neccessary.
This won't work in this case, only the primary encoding table
of the font will be used.
<p>

<h4><tt>
&nbsp;&nbsp;nsfilter<br>
&nbsp;&nbsp;nsprint<br>
&nbsp;&nbsp;psfonts.cf
</tt></h4>
<p>

These are the filters for printing from Netscape.
<p>

Changing the metrics is not the end of the story. This will
provide proper placement of the characters but not the
characters themselves. There are a few ways to provide
the characters:
<p>

First, if you use GhostScript you may configure proper
aliases in the GhostScript configuration file. We will
consider this variant trivial and won't discuss it furter
except for one caveat: Netscape tries to re-encode the
fonts per the ISO Latin-1 encoding. If the primary encoding
of the font is different this cause unexpected effects.
So you still may consider using the filters (at least in a
simplified form) to solve this problem.
<p>

Second, load the fonts right into your printer. This is
very much like configuring GhostScript.
<p>

Third, use the provided filters. The script `<tt>nsfilter</tt>'
reads the output of Netscape on its standard input and
puts the result to its standard output. It uses the same
configuration file `<tt>psfonts.cf</tt>' as `<tt>nsfix</tt>'. First it
looks for the configuration file in the user's home
directory (<tt>$HOME/.netscape/psfonts.cf</tt>) and if the
file it not there then the second guess is the system-wide
configuration file <tt>/usr/local/etc/psfonts.cf</tt>. The
script inserts the fonts into the output and also
removes the Netscape's experiments with the encodings.
<p>

`<tt>nsfilter</tt>' is generally intended to be ran by user, not by the 
printing subsystem. The reason is that the user may have
changed fonts in his Netscape and the printing subsystem
would have no way to access user's configuration file.
But if all the users are using the same fonts then it
may be incorporated into the printing subsystem and use
the system-wide configuration file.
<p>

The script `<tt>nsprint</tt>' is purely for convenience, to type it
as a printing command in the Netscape printing window.
It just pipelines the data through `<tt>nsfilter</tt>' to the
printing program which also gets all the arguments. Please 
note that the SystemV-style and BSD-style systems use different
printing programs (although they commonly provide compatibility
with the other style too). The script tries to guess the
type of system and use its native print program, `<tt>lp</tt>' or
`<tt>lpr</tt>'. But in case it guesses wrong you may want
to change this in the script.  Also if the printer does not support
PostScript directly this script may be a good place to
insert a call to GhostScript.
<p>

<h4><tt>
&nbsp;&nbsp;notscape<br>
&nbsp;&nbsp;fontsz.cf
</tt></h4>
<p>

Netscape on Unix has a very annoying "feature", it does
not remember the desired base size of the scalable screen
fonts and always resets it to 12.0 points. Even if the size
is changed manually in its preferences file, Netscape
forgets it after it exits. 
<p>

So my solution was to write a program which would change
the size to my favorite one every time right before
starting Netscape. `<tt>notscape</tt>' is exactly such a program,
it sets the font sizes an then transparently executes 
netscape. It takes the font sizes from the file
`<tt>$HOME/.netscape/fontsz.cf</tt>' . An example of such file
is provided. The format of the file is quite self-explanatory,
for example the lines
<p>

<tt>
fixed-koi8-r	140<br>
prop-koi8-r	150
</tt>
<p>

mean "set the size of the fixed-width screen font in the 
encoding koi8-r to 14.0 points; set the size of the proportional 
(variable-width) font in the encoding koi8-r to 15.0 points".
<p>


<h3><tt>
&nbsp;&nbsp;nspr
</tt><br>
by Zvezdan Petkovic</h3>
<p>

To print from Netscape, I usually print to the Postscript file first.
Then I use this small script to change the names of Times and Courier fonts
in the file and remove `/Encoding' lines.  After that the file can be
sent to printer.
<p>
</BODY>
</HTML>

